/// <reference path="../../../typings/index.d.ts" />


//获取应用实例
const key = 'BZVBZ-JRS6O-OJTWO-SADRH-TSHY2-5PBAJ'; //使用在腾讯位置服务申请的key
const referer = 'bash'; //调用插件的app的名称
const category = '生活服务,娱乐休闲';
export const chooseLocation = requirePlugin('chooseLocation');

/**
 * 调用地图插件，返回位置
 * @returns `location{name, latitude, longtitude, address, province, city, district}`
 */
export function navigateToMap() {
    let location = "";
    wx.getLocation({
        type: 'gcj02',
        altitude: true,//可以返回高度信息
        //定位成功，更新定位结果
        success: function (res) {
            let latitude = res.latitude;
            let longitude = res.longitude;
            let speed = res.speed;
            let accuracy = res.accuracy;
            location = JSON.stringify({
                latitude: latitude,
                longitude: longitude
            });
            console.log(location);
            console.log(latitude, longitude, speed, accuracy);
        },

        //定位失败回调
        fail: function () {
            wx.showToast({
                title: "定位失败",
                icon: "none"
            })
        },
        complete: function () {
            //隐藏定位中信息进度
            wx.hideLoading();
        }
    });
    wx.navigateTo({
        url: 'plugin://chooseLocation/index?key=' + key + '&referer=' + referer + '&location=' + location + '&category=' + category
    });
    // return chooseLocation.getLocation(); // 如果点击确认选点按钮，则返回选点结果对象，否则返回null
}

